﻿<!DOCTYPE html>
<html lang="zh_CN">

<head>
    <title>文本间距maxWidth</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="图形系统开发实战:进阶篇 示例">
    <meta name="author" content="hjq">
    <meta name="keywords" content="canvas,anygraph,javascript">
    <!-- frame所需脚本和样式 -->
    <link rel="stylesheet" href="../../script/bootstrap-3.3.5/css/bootstrap.min.css">   
    <link rel="stylesheet" href="../../script/codemirror/codemirror.css">
    <script src="../../script/lib/jquery-1.11.2.min.js"></script>
    <script src="../../script/codemirror/codemirror_merge.js"></script>
    <!-- 加载代码块 -->
    <link rel="stylesheet" href="../css/styles.css">
    <script src="../js/data_box.js"></script>
    <script src="../js/helper.js"></script>
    <script>
        var pageTitle = "文本间距";
        var pageDesc = "文本的maxWidth属性";
    </script>
</head>

<body style="margin:10px;">
    <div id="graphWrapper" data-type="graph" style="width:550px; height:280px; border:solid 1px #CCC;"></div>
    <h3>Data</h3>
    <div id="divData" style="height:120;"></div>
</body>

<script>
    let graph;
</script>
<script type="module">
    import { Graph, Circle, Text, Rect, BgUtil } from "../../src/index.js";

    // graph对象
    graph = new Graph({
        "target": "graphWrapper",
        "enabledGeomEvent": true
    });

    // 网格水印层
    BgUtil.generateGrid(Object.assign({ "interval": 10, "graph":graph }, graph.getSize()));
    
    // 新建绘图图层
    let layer = graph.addLayer();

    // 绘制填充的文字
    layer.getSource().add(new Text({ "x": 60, "y": 60, "text": "图形系统开发实战: draw text", "style": { "textBaseline": "top", "fillColor": "#000000", "fontSize": 30, "fontName": "Inconsolata", "fontBold":true } }));
    layer.getSource().add(new Text({ "x": 60, "y": 130, "text": "图形系统开发实战: draw text", "maxWidth":300, "style": { "textBaseline": "top", "fillColor": "#000000", "fontSize": 30, "fontName": "Inconsolata", "fontBold":true  } }));
    layer.getSource().add(new Text({ "x": 60, "y": 200, "text": "图形系统开发实战: draw text", "maxWidth":200, "style": { "textBaseline": "top", "fillColor": "#000000", "fontSize": 30, "fontName": "Inconsolata", "fontBold":true  } }));

    layer.getSource().add(new Rect({ "x": 60, "y": 130, "width":300, "height":30, "style": { "color": "red" } }));
    layer.getSource().add(new Rect({ "x": 60, "y": 200, "width":200, "height":30, "style": { "color": "red" } }));

    // 为geom绑定click事件
    let geoms = layer.getSource().getData();
    geoms.forEach( geom => {
		geom.on("click", activeShape);
	})
	
    graph.render();
</script>

</html>